package com.blacktry.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.entity.model.CourseInfo;
import com.blacktry.entity.model.Vo.Courseinformation;
import com.blacktry.entity.model.Vo.Courseinformation2;
import com.blacktry.service.CourseInfoService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author blackTry
 * @since 2021-12-12
 */
@RestController
@RequestMapping("/course-info")
@Api(value = "教师课程模块", tags = "教师课程接口")
public class CourseInfoController {


    @Autowired
    private CourseInfoService courseInfoService;
    //查询所有教师和授课信息
    @OperLog(operModul = "教师课程管理-查询所有教师课程关联信息",operType = OprLogConst.SELECT,operDesc = "查询所有教师课程关联信息")
    @ApiOperation("查询所有教师课程关联信息")
    @PostMapping("/select/{page}/{size}")
    public ApiResult<Page<CourseInfo>> select(@RequestBody CourseInfo courseInfo, @PathVariable Integer page, @PathVariable Integer size) {
        return ApiResultHandler.buildApiResult(200, "成功",
                courseInfoService.
                        selectInfo(courseInfo.getCourseId(),courseInfo.getUserId(),
                                new Page<CourseInfo>(page,size)));
    }



    //根据教师查询可授的课程
    @OperLog(operModul = "教师课程管理-查询课程的教师课程关联信息",operType = OprLogConst.SELECT,operDesc = "查询课程的教师课程关联信息")
    @ApiOperation("查询课程的教师课程关联信息")
    @PostMapping("/selectCourse/{page}/{size}")
    public ApiResult<Page<Courseinformation>> selectCourse(@RequestBody CourseInfo courseInfo, @PathVariable Integer page, @PathVariable Integer size) {
        return ApiResultHandler.buildApiResult(200, "成功",
                courseInfoService.selectCourse(courseInfo.getUserId(),
                                new Page<Courseinformation>(page,size)));
    }


    //根据课程查询可授的教师
    @OperLog(operModul = "教师课程管理-查询教师的教师课程关联信息",operType = OprLogConst.SELECT,operDesc = "查询教师的教师课程关联信息")
    @ApiOperation("查询教师的教师课程关联信息")
    @PostMapping("/selectUser/{page}/{size}")
    public ApiResult<Page<Courseinformation2>> selectUser(@RequestBody CourseInfo courseInfo, @PathVariable Integer page, @PathVariable Integer size) {
        return ApiResultHandler.buildApiResult(200, "成功",
                courseInfoService.selectUser(courseInfo.getCourseId(),
                        new Page<Courseinformation2>(page,size)));

    }

    @OperLog(operModul = "教师课程管理-为某个课程分配多个教师",operType = OprLogConst.ADD,operDesc = "为某个课程分配多个教师")
    @ApiOperation("为某个课程分配多个教师")
    @GetMapping("/addCourseInfo/{courseId}")
    public ApiResult addCourseInfo(@PathVariable("courseId")String courseId,String[] ids) {
        for (String username : ids) {
            CourseInfo courseInfo = new CourseInfo();
            courseInfo.setCourseId(courseId);
            courseInfo.setUserId(username);
            courseInfoService.save(courseInfo);
        }
        return ApiResultHandler.buildApiResult(200, "成功");

    }



}

